<?php

namespace App\Validate;

/**
 * 验证抽象类
 */
abstract class ValidateInterface {
    /**
     * 验证场景
     * @param $scene
     * @return mixed
     */
    abstract public static function scene($scene);

    static $rules       = [ /* 'mobile' => 'required|regex:/^1\d{10}$/' */ 
    ];
    static $rules_format = [ /* 'mobile.regex' => '手机号格式不对' */ 
    ];
    static $rules_str     = [ /* 'mobile' => '手机号' */ 
    ];

    /** 借助ValidationException实现验证拦截, App\Exceptions\Handler中复写$e instanceof ValidationException  */
    protected static function validate(array $keys) {
        foreach($keys as $k) { $result[$k] = static::$rules[$k]; }
        request()->validate($result, static::$rules_format, static::$rules_str);
    }

}
